package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.mapper.CustomerMapper;
import cn.wolfcode.crm.query.CustomerQueryObject;
import cn.wolfcode.crm.service.ICustomerService;
import cn.wolfcode.crm.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements ICustomerService {

	@Autowired
	private CustomerMapper customerMapper;
	@Override
	public void deleteByPrimaryKey(Long id) {

		customerMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void insert(Customer entity) {


		entity.setInputUser(UserContext.getCurrentUser());
		entity.setInputTime(new Date());
		entity.setSeller(UserContext.getCurrentUser());

		customerMapper.insert(entity);
	}

	@Override
	public Customer selectByPrimaryKey(Long id) {

		return customerMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Customer> selectAll() {

		return customerMapper.selectAll();
	}

	@Override
	public void updateByPrimaryKey(Customer entity) {

		customerMapper.updateByPrimaryKey(entity);
	}

	@Override
	public PageInfo query(CustomerQueryObject qo) {
		//查询总记录数

		PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(),qo.getOrderBy());
		List<Customer> data = customerMapper.queryForList(qo);
		return new PageInfo<Customer>(data);
	}

}
